fix: forward process.stdin to child when no explicit input is provided#1420
Open
fresh3nough wants to merge 2 commits intogoogle:mainfrom
Open
fix: forward process.stdin to child when no explicit input is provided#1420fresh3nough wants to merge 2 commits intogoogle:mainfrom
fresh3nough wants to merge 2 commits intogoogle:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1378
When using
$cat`` or any interactive command via zx's$, the child process's stdin was not connected to the parent's stdin. This meant interactive commands could not read from the terminal, unlike standard shell behavior.Root cause
The default
stdiois'pipe', which creates a new pipe for stdin. However, nothing connectedprocess.stdinto the child's stdin pipe -- the child received an emptyVoidStreaminstead.Fix
In the
ProcessPromise.run()method'sstarthandler, after the child process spawns,process.stdinis now piped tochild.stdinwhen all of the following conditions are met:$.inputis providedchild.stdinexists and is not destroyed (stdio[0]is'pipe')process.stdinis readable and has not endedProcessPromiseCleanup is handled automatically: errors on
child.stdinare suppressed via a noop handler, andprocess.stdinis unpiped when the child closes.How to reproduce
Run the script, type something, press Enter -- previously nothing happened. Now it echoes input and responds to Ctrl+D (EOF) as expected.
Tests
Added integration test: spawns a child Node.js process running
$cat``, writes to its stdin, and verifies the output is forwarded correctly.All 28 existing stdin and pipe tests continue to pass.
Setup Set the latest Node.js LTS version.
Build: I've run
npm buildbefore committing and verified the bundle updates correctly.Tests: I've run
testand confirmed all tests succeed. Added tests to cover my changes if needed.Docs: I've added or updated relevant documentation as needed.
Sign Commits have verified signatures and follow conventional commits spec
CoC: My changes follow the project's coding guidelines and Code of Conduct.
Review: This PR represents original work and is not solely generated by AI tools.